namespace SiliverlightJavascriptIntelli
{
    public static class JavascriptStaticFormats
    {
        public static string TypeSafety
        {
            get
            {
                return
                    @"function TypeSafety(paramsToValidate)
{
    var isValid = true;
    for(var paramType  in paramsToValidate)
    {
        var paramValue = paramsToValidate[paramType];
        var ConvertIs = eval(""Convert.Is"" + paramType);
        if (ConvertIs)
        {
           if (!ConvertIs(paramValue))
           {
                isValid = false;
           }
        }
        
        if ((paramType == ""String"") && !IsString(paramValue))
            isValid = false;
       
        if (((paramType == ""Number"") || (paramType == ""Double"")) && !IsNumber(paramValue))
            isValid = false;
            
        if ((paramType == ""Function"") && !IsFunction(paramValue))
            isValid = false;
              
        if ((paramType == ""Boolean"") && !IsBoolean(paramValue))
            isValid = false;
                  
        if (!isValid)
            throw new Error(paramValue + "" is not of type "" + paramType);
    }
}

function IsPrimitive(value) 
{ 
    return IsString(value) || IsNumber(value) || IsFunction(value) || IsBoolean(value); 
}

function IsString(value) 
{ 
    return (value  != null) && (value.toLowerCase != null); 
}

function IsNumber(value) 
{
    return (value != null) && (value.toPrecision != null);
}

function IsFunction(value) 
{
    return  (value != null) && (value.apply != null); 
}

function IsBoolean(value) 
{ 
    return (value != null) && ((value == true) || (value == false)); 
}

function HasElementProperty(value)
{
    try {  return (value != null) && (value.element != null); }
    catch(ex) { return false;  }
}

function CheckConvertIs(typeHierchy, javascriptObject, canBePrimitive)
{
        if (!javascriptObject)
            return false;
        if (!javascriptObject.toString())
            return false;
        var IsInTypeHierchy = typeHierchy.indexOf(',' + javascriptObject.toString() + ',') != -1;
        if (IsInTypeHierchy)
            return true;
        if (canBePrimitive)
        {
            if (HasElementProperty(javascriptObject))
                return IsPrimitive(javascriptObject.element);
            else
                return IsPrimitive(javascriptObject);
        }
                
}
" + JavascriptFormats.BreakLine;
            }
        }



        public static string HostTypes
        {
            get
            {
                return
@"
Host = function(HostXamlElement) 
{
        /// <summary></summary>
        /// <param name=""HostXamlElement"">Non strongly typed Xaml Element</param>
        this.element = HostXamlElement;
}

Host.prototype.get_initParams = function()
{
    /// <summary>Specifies a string that represents a set of user-defined initialization parameters. The string format of the params value is user-defined.</summary>
    /// <returns type=""String"" integer=""False"" />   
    return (this.element.initParams);
}

Host.prototype.get_isLoaded = function()
{
    /// <summary>true if the Silverlight control is loaded; otherwise, false. The IsLoaded property is set to true after the XAML content in the Silverlight control has completely loaded, but before the OnLoad event occurs.</summary>
    /// <returns type=""Boolean"" integer=""False"" />   
    return (this.element.isLoaded);
}

Host.prototype.get_source = function()
{
    /// <summary>Specifies the XAML content to render.</summary>
    /// <returns type=""String"" integer=""False"" />   
    return (this.element.source);
}

Host.prototype.get_content = function()
{
    /// <summary></summary>
    /// <returns type=""Content"" integer=""False"" />   
    return new Content(this.element.content);
}

Host.prototype.get_settings = function()
{
    /// <summary></summary>
    /// <returns type=""Settings"" integer=""False"" />   
    return new Settings(this.element.settings);
}

Host.prototype.createObject = function(objectType)
{
     /// <summary>The Downloader object is the only object that can by specified as the objectType parameter for the CreateObject method. If you specify an invalid objectType parameter, the CreateObject method throws an exception.An object reference if the object was successfully created.</summary>
    /// <param name=""objectType"" type=""String"" integer=""False"" >The type of object to create.</param>   
    /// <returns type=""Downloader"" integer=""False"" />   
    TypeSafety({""String"":objectType});
    return Convert.ToDownloader(this.element.createObject(objectType));
}

Host.prototype.add_OnError = function(handler) {
    /// <summary>Occurs when the Silverlight control generates a runtime error.</summary>
    /// <param name=""handler"" type=""Function"" />
    /// <returns type=""Number"">eventId</returns>
    TypeSafety({""Function"" : handler});
    this.element.OnError = handler;
}

Host.prototype.get_element = function()
{
    /// <returns>Non intellisensed XAML object</returns>
    return this.element; 
}

Content = function(ContentXamlElement) 
{
        /// <summary></summary>
        /// <param name=""ContentXamlElement"">Non strongly typed Xaml Element</param>
        this.element = ContentXamlElement;
}

Content.prototype.get_actualHeight = function()
{
    /// <summary>Specifies the height of the rendering area of the Silverlight control.</summary>
    /// <returns type=""Number"" integer=""True"" />   
    return (this.element.actualHeight);
}

Content.prototype.get_actualWidth = function()
{
    /// <summary>Specifies the width of the rendering area of the Silverlight control.</summary>
    /// <returns type=""Number"" integer=""True"" />   
    return (this.element.actualWidth);
}

Content.prototype.set_fullScreen = function(value)
{
    /// <summary>Determines whether the Silverlight control displays as a full-screen control.</summary>
    /// <param name=""value"" type=""Boolean"" integer=""False"" />
    TypeSafety({""Boolean"" : value});   
    this.element.fullScreen = value;
}

Content.prototype.get_fullScreen = function()
{
    /// <summary>Determines whether the Silverlight control displays as a full-screen control.</summary>
    /// <returns type=""Boolean"" integer=""False"" />   
    return (this.element.fullScreen);
}

Content.prototype.findName = function(objectName)
{
     /// <summary>Gets any object in the Silverlight object hierarchy by referencing the object's x:Name attribute value.A reference to the specified object if the object was successfully found; otherwise, returns null.</summary>
    /// <param name=""objectName"" type=""String"" integer=""False"" >The name of the object to get.</param>   
    /// <returns type=""DependencyObject"" integer=""False"" />   
    TypeSafety({""String"":objectName});
    return Convert.ToDependencyObject(this.element.findName(objectName));
}

Content.prototype.createFromXaml = function(xamlContent, nameScope)
{
     /// <summary>Creates XAML content dynamically.An object reference if the XAML content was successfully created; otherwise, returns null.</summary>
    /// <param name=""xamlContent"" type=""String"" integer=""False"" >The XAML content to add to the existing Silverlight object hierarchy.</param>   
    /// <param name=""nameScope"" type=""Boolean"" integer=""False"" >Determines whether to create x:Name references in XAML content that do not conflict with other named elements. The nameScope parameter is optional, and its value defaults to false if not specified.</param>   
    /// <returns type=""DependencyObject"" integer=""False"" />   
    TypeSafety({""String"":xamlContent, ""Boolean"":nameScope});
    return Convert.ToDependencyObject(this.element.createFromXaml(xamlContent, nameScope));
}

Content.prototype.createFromXamlDownloader = function(downloader, part)
{
     /// <summary>Creates XAML content dynamically using downloader content.An object reference if the XAML content was successfully created; otherwise, returns null.</summary>
    /// <param name=""downloader"" type=""Downloader"" integer=""False"" >The object containing the downloaded content</param>   
    /// <param name=""part"" type=""String"" integer=""False"" >The name of the specific part of the downloaded content package. When the downloaded content package is a Zip file, part refers to the contents of a filename within downloader. If the downloaded content does not represent packaged content, set part to an empty string.</param>   
    /// <returns type=""DependencyObject"" integer=""False"" />   
    TypeSafety({""Downloader"":downloader, ""String"":part});
    return Convert.ToDependencyObject(this.element.createFromXamlDownloader(downloader.element, part));
}


Content.prototype.add_OnResize = function(handler) {
    /// <summary>Occurs whenever the ActualHeight or ActualWidth property of the Silverlight control changes.</summary>
    /// <param name=""handler"" type=""Function"" />
    TypeSafety({""Function"" : handler});
    this.element.OnResize = handler;
}

Content.prototype.add_OnFullScreenChange = function(handler) {
    /// <summary>Occurs whenever the FullScreen property of the Silverlight control changes.</summary>
    /// <param name=""handler"" type=""Function"" />
    TypeSafety({""Function"" : handler});
    this.element.OnFullScreenChange = handler;
}
    
Content.prototype.get_element = function()
{
    /// <returns>Non intellisensed XAML object</returns>
    return this.element; 
}

Settings = function(SettingsXamlElement) 
{
        /// <summary></summary>
        /// <param name=""SettingsXamlElement"">Non strongly typed Xaml Element</param>
        this.element = SettingsXamlElement;
}

Settings.prototype.set_background = function(value)
{
    /// <summary>Specifies the background color of the rectangular region that display XAML content.</summary>
    /// <param name=""value"" type=""String"" integer=""False"" />
    TypeSafety({""String"" : value});   
    this.element.background = value;
}

Settings.prototype.get_background = function()
{
    /// <summary>Specifies the background color of the rectangular region that display XAML content.</summary>
    /// <returns type=""String"" integer=""False"" />   
    return (this.element.background);
}

Settings.prototype.set_enableFramerateCounter = function(value)
{
    /// <summary>Gets or sets a value that determines whether to display the current framerate in the hosting browser's status bar. (Microsoft Internet Explorer only)</summary>
    /// <param name=""value"" type=""Boolean"" integer=""False"" />
    TypeSafety({""Boolean"" : value});   
    this.element.enableFramerateCounter = value;
}

Settings.prototype.get_enableFramerateCounter = function()
{
    /// <summary>Gets or sets a value that determines whether to display the current framerate in the hosting browser's status bar. (Microsoft Internet Explorer only)</summary>
    /// <returns type=""Boolean"" integer=""False"" />   
    return (this.element.enableFramerateCounter);
}

Settings.prototype.set_enableRedrawRegions = function(value)
{
    /// <summary>Shows the areas of the plug-in that are being redrawn each frame.</summary>
    /// <param name=""value"" type=""Boolean"" integer=""False"" />
    TypeSafety({""Boolean"" : value});   
    this.element.enableRedrawRegions = value;
}

Settings.prototype.get_enableRedrawRegions = function()
{
    /// <summary>Shows the areas of the plug-in that are being redrawn each frame.</summary>
    /// <returns type=""Boolean"" integer=""False"" />   
    return (this.element.enableRedrawRegions);
}

Settings.prototype.set_enableHtmlAccess = function(value)
{
    /// <summary>Determines whether the hosted content in the Silverlight control has access to the browser Document Object Model (DOM).</summary>
    /// <param name=""value"" type=""Boolean"" integer=""False"" />
    TypeSafety({""Boolean"" : value});   
    this.element.enableHtmlAccess = value;
}

Settings.prototype.get_enableHtmlAccess = function()
{
    /// <summary>Determines whether the hosted content in the Silverlight control has access to the browser Document Object Model (DOM).</summary>
    /// <returns type=""Boolean"" integer=""False"" />   
    return (this.element.enableHtmlAccess);
}

Settings.prototype.set_maxFrameRate = function(value)
{
    /// <summary>Specifies the maximum number of frames to render per second.</summary>
    /// <param name=""value"" type=""Number"" integer=""True"" />
    TypeSafety({""Number"" : value});   
    this.element.maxFrameRate = value;
}

Settings.prototype.get_maxFrameRate = function()
{
    /// <summary>Specifies the maximum number of frames to render per second.</summary>
    /// <returns type=""Number"" integer=""True"" />   
    return (this.element.maxFrameRate);
}

Settings.prototype.get_version = function()
{
    /// <summary>Gets the version of the Silverlight control.</summary>
    /// <returns type=""String"" integer=""False"" />   
    return (this.element.version);
}

Settings.prototype.get_windowless = function()
{
    /// <summary>Determines whether the Silverlight control displays as a window-less control.</summary>
    /// <returns type=""Boolean"" integer=""False"" />   
    return (this.element.windowless);
}

Settings.prototype.get_element = function()
{
    /// <returns>Non intellisensed XAML object</returns>
    return this.element; 
}


";
            }
        }
    }
}